<?php

namespace App\HttpController\Admin;

use App\HttpController\Base;
use App\Model\Service\CartService;
use App\Model\Service\CustomerService;

class Customer extends Base
{

    public function view()
    {
        $data = $this->service->view();
        $this->success($data);
    }

    public function list()
    {

        $dataPass = validateDateRange($this->postParams['date_start'], $this->postParams['date_end'], 31);

        if (!$dataPass['valid']) {
            return $this->error($dataPass['message']);
        }

        $data = $this->service->list();
        $this->success($data);
    }

    protected function getValidate(string $actionName): array
    {
        switch ($actionName) {
            case 'view':
                return [
                    'cus_id' => 'required,integer,notEmpty',
                ];
            case 'list':
            default:
                return [
                    'needPage' => 'required,notEmpty,integer',
                    'api_come' => 'required,notEmpty',
                    'biz_id' => 'required,integer,notEmpty',
                    'brand' => 'required',
                    'shop' => 'required',
                    'add_dept_id' => 'required',
                    'add_user_id' => 'required',
                    'operator_user_id' => 'required',
                    'operator_user_dept' => 'required',
                    'cus_type' => 'required',
                    'sex' => 'required',
                    'status' => 'required',
                    'date_type' => 'required,notEmpty',
                    'date_start' => 'required,notEmpty',
                    'date_end' => 'required,notEmpty',
                    'keyword' => 'required',
                    'keyword_type' => 'required,integer,notEmpty',
                    'is_del_follow_user' => 'required',
                    'kaikou_nums' => 'required',
                ];
        }
    }

    protected function initService(array $postParams, array $loginUser): void
    {
        $this->service = new CustomerService($postParams, $loginUser);
    }
}